home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 January / macformat-020.iso / Shareware City / Developers / OutOfPhase1.01Source / OutOfPhase Folder / Level 0 Macintosh 07Aug94 / Definitions.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-01  |  3.5 KB  |  96 lines  |  [TEXT/KAHL]

  1. /* Definitions.c */
  2. /*****************************************************************************/
  3. /*                                                                           */
  4. /*    System Dependency Library for Building Portable Software               */
  5. /*    Macintosh Version                                                      */
  6. /*    Written by Thomas R. Lawrence, 1993 - 1994.                            */
  7. /*                                                                           */
  8. /*    This file is Public Domain; it may be used for any purpose whatsoever  */
  9. /*    without restriction.                                                   */
  10. /*                                                                           */
  11. /*    This package is distributed in the hope that it will be useful,        */
  12. /*    but WITHOUT ANY WARRANTY; without even the implied warranty of         */
  13. /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                   */
  14. /*                                                                           */
  15. /*    Thomas R. Lawrence can be reached at tomlaw@world.std.com.             */
  16. /*                                                                           */
  17. /*****************************************************************************/
  18.  
  19. #include "MiscInfo.h"
  20. #include "Definitions.h"
  21. #include "Audit.h"
  22. #include "Debug.h"
  23.  
  24. #pragma options(pack_enums)
  25. #include <Memory.h>
  26. #pragma options(!pack_enums)
  27.  
  28.  
  29. /* move data.  The data can be overlapping. */
  30. void                MoveData(char* Source, char* Destination, long NumBytes)
  31.     {
  32. #if DEBUG && !defined(__cplusplus)
  33.         Zone*                Zone;
  34.         char*                ZoneBeginning;
  35.         char*                ZoneEnd;
  36.  
  37.         /* a handy error check:  make sure the source and destination are actually */
  38.         /* in the bounds of the heap.  (debugging suppresses allocation of data */
  39.         /* from temporary memory) */
  40.         Zone = GetZone();
  41.         ZoneBeginning = (char*)&(Zone->heapData);
  42.         asm
  43.             {
  44.                 move.l a5,ZoneEnd
  45.             }
  46.         if ((ZoneBeginning > (char*)Source)
  47.             || (ZoneEnd <= (char*)Source + NumBytes)
  48.             || (ZoneBeginning > (char*)Destination)
  49.             || (ZoneEnd <= (char*)Destination + NumBytes))
  50.             {
  51.                 APRINT(("!MoveData %r->%r(+%l) [%r..%r]",Source,Destination,NumBytes,
  52.                     ZoneBeginning,ZoneEnd));
  53.                 PRERR(ForceAbort,"MoveData:  source or destination beyond heap limits!");
  54.             }
  55. #endif
  56.  
  57.         ERROR(NumBytes < 0,PRERR(ForceAbort,
  58.             "MoveData:  Request to move negative number of bytes"));
  59.         BlockMove(Source,Destination,NumBytes);
  60.     }
  61.  
  62.  
  63. /* copy data.  the regions can NOT be overlapping and an error will result */
  64. /* if they are */
  65. void                CopyData(char* Source, char* Destination, long NumBytes)
  66.     {
  67. #if DEBUG && !defined(__cplusplus)
  68.         Zone*                Zone;
  69.         char*                ZoneBeginning;
  70.         char*                ZoneEnd;
  71.  
  72.         Zone = GetZone();
  73.         ZoneBeginning = (char*)&(Zone->heapData);
  74.         asm
  75.             {
  76.                 move.l a5,ZoneEnd
  77.             }
  78.         if ((ZoneBeginning > (char*)Source)
  79.             || (ZoneEnd <= (char*)Source + NumBytes)
  80.             || (ZoneBeginning > (char*)Destination)
  81.             || (ZoneEnd <= (char*)Destination + NumBytes))
  82.             {
  83.                 APRINT(("!CopyData %r->%r(+%l) [%r..%r]",Source,Destination,NumBytes,
  84.                     ZoneBeginning,ZoneEnd));
  85.                 PRERR(ForceAbort,"CopyData:  source or destination beyond heap limits!");
  86.             }
  87. #endif
  88.  
  89.         ERROR(NumBytes < 0,PRERR(ForceAbort,
  90.             "CopyData:  Request to move negative number of bytes"));
  91.         ERROR(((Source <= Destination) && (Source + NumBytes > Destination))
  92.             || ((Destination <= Source) && (Destination + NumBytes > Source)),
  93.             PRERR(ForceAbort,"CopyData:  Request to copy overlapping blocks"));
  94.         BlockMove(Source,Destination,NumBytes);
  95.     }
  96.